package com.brush.framework.config;

import com.brush.common.core.domain.req.AppLoginReq;
import com.brush.framework.web.service.AppUserThreadLocal;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 自定义密码认证算法
 *
 * @author tonneyyy
 */
public class AppPasswordEncoder extends BCryptPasswordEncoder {


    /**
     * 重写逻辑
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        //得到当前登录的用户信息
        AppLoginReq appLoginReq =  AppUserThreadLocal.APP_USER_THREAD_LOCAL.get();
        //密码登录
        if(appLoginReq.getType()==1){
            return super.matches(rawPassword, encodedPassword);
        }
        return true;
    }
}
